/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Telas;

import Beans.BeanPessoa;
import CRUD.CRUDPessoa;
import ClassesExtras.LetrasMaiusculas;
import ClassesExtras.TextAreaMaiuscula;

import java.awt.Color;
import java.awt.Dimension;
import static java.awt.Frame.MAXIMIZED_BOTH;
import java.awt.Toolkit;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

/**
 *
 * @author Marcos
 */
public class Fr_CadastroPessoa extends javax.swing.JFrame {

    
    
    public static String dataTexto, cod_cidade, den_cidade, estado;

    /**
     * Creates new form Fr_CadastroPessoa
     */
    public Fr_CadastroPessoa() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupTPPessoa = new javax.swing.ButtonGroup();
        jLabelCodigo = new javax.swing.JLabel();
        jTextFieldCodigo = new javax.swing.JTextField();
        jLabelNome = new javax.swing.JLabel();
        jTextFieldNome = new LetrasMaiusculas();
        jLabelTpSangue = new javax.swing.JLabel();
        jComboBoxTpSangue = new javax.swing.JComboBox();
        jLabelCadastro = new javax.swing.JLabel();
        jTextFieldCadastro = new javax.swing.JTextField();
        jLabelNascimento = new javax.swing.JLabel();
        jFormattedTextFieldNascimento = new javax.swing.JFormattedTextField();
        jLabelIdade = new javax.swing.JLabel();
        jTextFieldIdade = new javax.swing.JTextField();
        jLabelSexo = new javax.swing.JLabel();
        jComboBoxSexo = new javax.swing.JComboBox();
        jLabelEstadoCivil = new javax.swing.JLabel();
        jComboBoxEstadoCivil = new javax.swing.JComboBox();
        jLabelNaturalidade = new javax.swing.JLabel();
        jTextFieldNaturalidade = new LetrasMaiusculas();
        jLabelCor = new javax.swing.JLabel();
        jTextFieldCor = new LetrasMaiusculas();
        jLabelRG = new javax.swing.JLabel();
        jTextFieldIdentitade = new javax.swing.JTextField();
        jLabelCPF = new javax.swing.JLabel();
        jFormattedTextFieldCPF = new javax.swing.JFormattedTextField();
        jLabelEmail = new javax.swing.JLabel();
        jTextFieldEMail = new LetrasMaiusculas();
        jPanalEndereco = new javax.swing.JPanel();
        jLabelEndereco = new javax.swing.JLabel();
        jTextFieldEndereco = new LetrasMaiusculas();
        jTextFieldCidade = new javax.swing.JTextField();
        jLabelCidade = new javax.swing.JLabel();
        jLabelBairro = new javax.swing.JLabel();
        jTextFieldBairro = new LetrasMaiusculas();
        jTextFieldCodCidade = new javax.swing.JTextField();
        jTextFieldEstado = new javax.swing.JTextField();
        jButtonConsultaCidade = new javax.swing.JButton();
        jLabelComplemento = new javax.swing.JLabel();
        jTextFieldComplemento = new LetrasMaiusculas();
        jPanelContato = new javax.swing.JPanel();
        jLabelTelefone = new javax.swing.JLabel();
        jFormattedTextFieldTelefone = new javax.swing.JFormattedTextField();
        jLabelCelular = new javax.swing.JLabel();
        jFormattedTextFieldCelular = new javax.swing.JFormattedTextField();
        jLabelObservacao = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextAreaObservacoes = new TextAreaMaiuscula();
        jButtonIncluir = new javax.swing.JButton();
        jButtonAlterar = new javax.swing.JButton();
        jButtonConsultar = new javax.swing.JButton();
        jButtonExcluir = new javax.swing.JButton();
        jPanelTPPessoa = new javax.swing.JPanel();
        jRadioButtonPaciente = new javax.swing.JRadioButton();
        jRadioButtonMedico = new javax.swing.JRadioButton();
        jRadioButtonFuncionario = new javax.swing.JRadioButton();
        jPanelMedico = new javax.swing.JPanel();
        jLabelCRM = new javax.swing.JLabel();
        jTextFieldCRM = new javax.swing.JTextField();
        jPanelPaciente = new javax.swing.JPanel();
        jLabelConvenio = new javax.swing.JLabel();
        jTextFieldConvenio = new javax.swing.JTextField();
        jPanelFuncionario = new javax.swing.JPanel();
        jTextFieldCarteiraTrabalho = new javax.swing.JTextField();
        jLabelCarteiraTrabalho = new javax.swing.JLabel();
        jLabelBarraStatus = new javax.swing.JLabel();
        jButtonFechar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de Pessoa");
        setUndecorated(true);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabelCodigo.setText("Código:");

        jTextFieldCodigo.setBackground(new java.awt.Color(255, 204, 204));
        jTextFieldCodigo.setEnabled(false);

        jLabelNome.setText("Nome:");

        jTextFieldNome.setVerifyInputWhenFocusTarget(false);
        jTextFieldNome.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldNomeActionPerformed(evt);
            }
        });

        jLabelTpSangue.setText("Sangue:");

        jComboBoxTpSangue.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "A+", "B+", "AB+", "O+", "A-", "B-", "AB-", "O-" }));

        jLabelCadastro.setText("Cadastro:");

        jTextFieldCadastro.setEnabled(false);

        jLabelNascimento.setText("Nascimento:");

        try {
            jFormattedTextFieldNascimento.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jFormattedTextFieldNascimento.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jFormattedTextFieldNascimentoFocusLost(evt);
            }
        });

        jLabelIdade.setText("Idade:");

        jLabelSexo.setText("Sexo:");

        jComboBoxSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Masculino", "Feminino" }));

        jLabelEstadoCivil.setText("Est Civil:");

        jComboBoxEstadoCivil.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Solteiro", "Casado ", "Outros" }));

        jLabelNaturalidade.setText("Naturalidade:");

        jLabelCor.setText("Cor:");

        jLabelRG.setText("RG:");

        jLabelCPF.setText("CPF:");

        try {
            jFormattedTextFieldCPF.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jFormattedTextFieldCPF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFormattedTextFieldCPFActionPerformed(evt);
            }
        });
        jFormattedTextFieldCPF.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jFormattedTextFieldCPFFocusLost(evt);
            }
        });

        jLabelEmail.setText("Email:");

        jPanalEndereco.setBorder(javax.swing.BorderFactory.createTitledBorder("Endereço"));

        jLabelEndereco.setText("Endereço");

        jTextFieldCidade.setText("ARAPONGAS");
        jTextFieldCidade.setEnabled(false);

        jLabelCidade.setText("Cidade:");

        jLabelBairro.setText("Bairro:");

        jTextFieldCodCidade.setText("11");
        jTextFieldCodCidade.setEnabled(false);

        jTextFieldEstado.setText("PR");
        jTextFieldEstado.setEnabled(false);

        jButtonConsultaCidade.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Consultar.png"))); // NOI18N
        jButtonConsultaCidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConsultaCidadeActionPerformed(evt);
            }
        });

        jLabelComplemento.setText("Complemento:");

        javax.swing.GroupLayout jPanalEnderecoLayout = new javax.swing.GroupLayout(jPanalEndereco);
        jPanalEndereco.setLayout(jPanalEnderecoLayout);
        jPanalEnderecoLayout.setHorizontalGroup(
            jPanalEnderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanalEnderecoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanalEnderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanalEnderecoLayout.createSequentialGroup()
                        .addComponent(jLabelCidade)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldCodCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanalEnderecoLayout.createSequentialGroup()
                        .addComponent(jLabelComplemento)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldComplemento)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonConsultaCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(jLabelEndereco)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelBairro)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 8, Short.MAX_VALUE))
        );
        jPanalEnderecoLayout.setVerticalGroup(
            jPanalEnderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanalEnderecoLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanalEnderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanalEnderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jButtonConsultaCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanalEnderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabelCidade)
                            .addComponent(jTextFieldCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldCodCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanalEnderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelEndereco)
                        .addComponent(jLabelBairro)
                        .addComponent(jTextFieldBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanalEnderecoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelComplemento)
                    .addComponent(jTextFieldComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(98, 98, 98))
        );

        jPanelContato.setBorder(javax.swing.BorderFactory.createTitledBorder("Contato"));

        jLabelTelefone.setText("Telefone:");

        try {
            jFormattedTextFieldTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabelCelular.setText("Celular:");

        try {
            jFormattedTextFieldCelular.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        javax.swing.GroupLayout jPanelContatoLayout = new javax.swing.GroupLayout(jPanelContato);
        jPanelContato.setLayout(jPanelContatoLayout);
        jPanelContatoLayout.setHorizontalGroup(
            jPanelContatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelContatoLayout.createSequentialGroup()
                .addComponent(jLabelTelefone)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jFormattedTextFieldTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabelCelular)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jFormattedTextFieldCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 312, Short.MAX_VALUE))
        );
        jPanelContatoLayout.setVerticalGroup(
            jPanelContatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelContatoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelContatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelTelefone)
                    .addComponent(jFormattedTextFieldTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCelular)
                    .addComponent(jFormattedTextFieldCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabelObservacao.setText("Observaçoes");

        jTextAreaObservacoes.setColumns(1);
        jTextAreaObservacoes.setRows(5);
        jScrollPane1.setViewportView(jTextAreaObservacoes);

        jButtonIncluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Incluir.png"))); // NOI18N
        jButtonIncluir.setMnemonic('I');
        jButtonIncluir.setText("Incluir");
        jButtonIncluir.setToolTipText("Incluir");
        jButtonIncluir.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                jButtonIncluirMouseDragged(evt);
            }
        });
        jButtonIncluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonIncluirActionPerformed(evt);
            }
        });

        jButtonAlterar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Alterar.png"))); // NOI18N
        jButtonAlterar.setMnemonic('A');
        jButtonAlterar.setText("Alterar");
        jButtonAlterar.setToolTipText("Alterar");

        jButtonConsultar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Consultar.png"))); // NOI18N
        jButtonConsultar.setMnemonic('C');
        jButtonConsultar.setText("Consultar");
        jButtonConsultar.setToolTipText("Consultar");

        jButtonExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Excluir.png"))); // NOI18N
        jButtonExcluir.setMnemonic('E');
        jButtonExcluir.setText("Excluir");
        jButtonExcluir.setToolTipText("Excluir");

        jPanelTPPessoa.setBorder(javax.swing.BorderFactory.createTitledBorder("Tipo de Pessoa"));
        jPanelTPPessoa.setName(""); // NOI18N

        buttonGroupTPPessoa.add(jRadioButtonPaciente);
        jRadioButtonPaciente.setSelected(true);
        jRadioButtonPaciente.setText("Paciente");
        jRadioButtonPaciente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonPacienteActionPerformed(evt);
            }
        });

        buttonGroupTPPessoa.add(jRadioButtonMedico);
        jRadioButtonMedico.setText("Médico");
        jRadioButtonMedico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMedicoActionPerformed(evt);
            }
        });

        buttonGroupTPPessoa.add(jRadioButtonFuncionario);
        jRadioButtonFuncionario.setText("Funcionário");
        jRadioButtonFuncionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonFuncionarioActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelTPPessoaLayout = new javax.swing.GroupLayout(jPanelTPPessoa);
        jPanelTPPessoa.setLayout(jPanelTPPessoaLayout);
        jPanelTPPessoaLayout.setHorizontalGroup(
            jPanelTPPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTPPessoaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jRadioButtonPaciente)
                .addGap(18, 18, 18)
                .addComponent(jRadioButtonMedico)
                .addGap(18, 18, 18)
                .addComponent(jRadioButtonFuncionario)
                .addContainerGap(457, Short.MAX_VALUE))
        );
        jPanelTPPessoaLayout.setVerticalGroup(
            jPanelTPPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTPPessoaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTPPessoaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jRadioButtonPaciente)
                    .addComponent(jRadioButtonMedico)
                    .addComponent(jRadioButtonFuncionario))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanelMedico.setBorder(javax.swing.BorderFactory.createTitledBorder("Médico"));

        jLabelCRM.setText("CRM:");

        javax.swing.GroupLayout jPanelMedicoLayout = new javax.swing.GroupLayout(jPanelMedico);
        jPanelMedico.setLayout(jPanelMedicoLayout);
        jPanelMedicoLayout.setHorizontalGroup(
            jPanelMedicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelMedicoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelCRM)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldCRM, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelMedicoLayout.setVerticalGroup(
            jPanelMedicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelMedicoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabelCRM)
                .addComponent(jTextFieldCRM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanelPaciente.setBorder(javax.swing.BorderFactory.createTitledBorder("Paciente"));

        jLabelConvenio.setText("Convênio com:");

        javax.swing.GroupLayout jPanelPacienteLayout = new javax.swing.GroupLayout(jPanelPaciente);
        jPanelPaciente.setLayout(jPanelPacienteLayout);
        jPanelPacienteLayout.setHorizontalGroup(
            jPanelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPacienteLayout.createSequentialGroup()
                .addComponent(jLabelConvenio)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldConvenio, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanelPacienteLayout.setVerticalGroup(
            jPanelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPacienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jTextFieldConvenio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabelConvenio))
        );

        jPanelFuncionario.setBorder(javax.swing.BorderFactory.createTitledBorder("Funcionário"));

        jLabelCarteiraTrabalho.setText("Carteira Trabalho:");

        javax.swing.GroupLayout jPanelFuncionarioLayout = new javax.swing.GroupLayout(jPanelFuncionario);
        jPanelFuncionario.setLayout(jPanelFuncionarioLayout);
        jPanelFuncionarioLayout.setHorizontalGroup(
            jPanelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelFuncionarioLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelCarteiraTrabalho)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldCarteiraTrabalho, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelFuncionarioLayout.setVerticalGroup(
            jPanelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFuncionarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabelCarteiraTrabalho)
                .addComponent(jTextFieldCarteiraTrabalho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jLabelBarraStatus.setFont(new java.awt.Font("sansserif", 1, 12)); // NOI18N
        jLabelBarraStatus.setForeground(new java.awt.Color(255, 0, 51));

        jButtonFechar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/Fechar.png"))); // NOI18N
        jButtonFechar.setMnemonic('f');
        jButtonFechar.setText("Fechar");
        jButtonFechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFecharActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelPaciente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelMedico, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelFuncionario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButtonIncluir, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonAlterar, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonFechar))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelTPPessoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 745, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanelContato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanalEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabelCadastro)
                                    .addComponent(jLabelCodigo)
                                    .addComponent(jLabelNaturalidade))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(jTextFieldCodigo)
                                            .addComponent(jTextFieldCadastro, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabelNome)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabelTpSangue)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jComboBoxTpSangue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabelSexo)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jComboBoxSexo, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jLabelNascimento)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jFormattedTextFieldNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabelIdade)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jTextFieldIdade, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabelEstadoCivil)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jComboBoxEstadoCivil, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabelCor)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jTextFieldCor))))
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jTextFieldNaturalidade, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabelRG)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldIdentitade, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabelCPF)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jFormattedTextFieldCPF, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabelEmail)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldEMail))))
                            .addComponent(jLabelBarraStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 426, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabelObservacao))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanelTPPessoa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabelNome)
                    .addComponent(jTextFieldNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelTpSangue)
                    .addComponent(jComboBoxTpSangue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelSexo)
                    .addComponent(jComboBoxSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelCadastro)
                    .addComponent(jTextFieldCadastro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelNascimento)
                    .addComponent(jFormattedTextFieldNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelIdade)
                    .addComponent(jTextFieldIdade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelEstadoCivil)
                    .addComponent(jComboBoxEstadoCivil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelCor)
                    .addComponent(jTextFieldCor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelNaturalidade)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldNaturalidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelRG)
                        .addComponent(jTextFieldIdentitade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelCPF)
                        .addComponent(jFormattedTextFieldCPF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabelEmail)
                        .addComponent(jTextFieldEMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanalEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelContato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelObservacao)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanelFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelMedico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanelPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButtonFechar, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButtonIncluir)
                        .addComponent(jButtonAlterar)
                        .addComponent(jButtonConsultar)
                        .addComponent(jButtonExcluir)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelBarraStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        //this.setExtendedState(Fr_Principal.MAXIMIZED_BOTH);
        
        
        Dimension tela = Toolkit.getDefaultToolkit().getScreenSize();
        setSize(760, 610);
        setLocation((tela.width - this.getSize().width) / 2, (tela.height - this.getSize().height) / 2);
        
        //setExtendedState(MAXIMIZED_BOTH);

        jPanelMedico.setVisible(false);
        jPanelFuncionario.setVisible(false);

        this.setLocationRelativeTo(null);

        Date data = new Date(System.currentTimeMillis());
        SimpleDateFormat formatarDate = new SimpleDateFormat("dd/MM/yyyy");
        jTextFieldCadastro.setText(formatarDate.format(data));
        jTextAreaObservacoes.setLineWrap(true);
    }//GEN-LAST:event_formWindowOpened

    private void jButtonConsultaCidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConsultaCidadeActionPerformed
        Fr_ConsultaCidade CC = new Fr_ConsultaCidade();
        CC.setVisible(true);
    }//GEN-LAST:event_jButtonConsultaCidadeActionPerformed

    private void jButtonIncluirMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonIncluirMouseDragged
        //        jButtonIncluir.setLocation(jButtonIncluir.getX() + evt.getX(), jButtonIncluir.getY() + evt.getY());
    }//GEN-LAST:event_jButtonIncluirMouseDragged

    private void jButtonIncluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonIncluirActionPerformed
        if (jTextFieldNome.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "O campo nome precisa ser preenchido!", "Atenção", JOptionPane.WARNING_MESSAGE);
            jTextFieldNome.setBackground(new Color(255, 204, 204));
        } else if (!jTextFieldNome.getText().equals("") && jFormattedTextFieldNascimento.getText().equals("  /  /    ")) {
            JOptionPane.showMessageDialog(null, "O campo Data de Nascimento precisa ser preenchido!", "Atenção", JOptionPane.WARNING_MESSAGE);
            jFormattedTextFieldNascimento.setBackground(new Color(255, 204, 204));
        } else if (!jTextFieldNome.getText().equals("") && !jFormattedTextFieldNascimento.getText().equals("  /  /    ") && jTextFieldIdentitade.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "O campo Identidade precisa ser preenchido!", "Atenção", JOptionPane.WARNING_MESSAGE);
            jTextFieldIdentitade.setBackground(new Color(255, 204, 204));
        } else if (!jTextFieldNome.getText().equals("") && !jFormattedTextFieldNascimento.getText().equals("  /  /    ") && !jTextFieldIdentitade.getText().equals("") && jFormattedTextFieldCPF.getText().equals("   .   .   -  ")) {
            JOptionPane.showMessageDialog(null, "O campo CPF precisa ser preenchido!", "Atenção", JOptionPane.WARNING_MESSAGE);
            jFormattedTextFieldCPF.setBackground(new Color(255, 204, 204));
        } else if (!jTextFieldNome.getText().equals("") && !jFormattedTextFieldNascimento.getText().equals("  /  /    ") && !jTextFieldIdentitade.getText().equals("") && !jFormattedTextFieldCPF.getText().equals("   .   .   -  ") && jTextFieldCodCidade.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "O campo Cidade precisa ser preenchido!", "Atenção", JOptionPane.WARNING_MESSAGE);
            jTextFieldCodCidade.setBackground(new Color(255, 204, 204));
            jTextFieldCidade.setBackground(new Color(255, 204, 204));
            jTextFieldEstado.setBackground(new Color(255, 204, 204));
        } else if (!jTextFieldNome.getText().equals("") && !jFormattedTextFieldNascimento.getText().equals("  /  /    ") && !jTextFieldIdentitade.getText().equals("") && !jFormattedTextFieldCPF.getText().equals("   .   .   -  ") && !jTextFieldCodCidade.getText().equals("") && jTextFieldEndereco.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "O campo Endereço precisa ser preenchido!", "Atenção", JOptionPane.WARNING_MESSAGE);
            jTextFieldEndereco.setBackground(new Color(255, 204, 204));
        } else {
            cadastro();
        }

        /*
         JFileChooser file = new JFileChooser();
         file.setFileSelectionMode(JFileChooser.FILES_ONLY);
         int i = file.showSaveDialog(null);
         if (i == 1) {
         jTextField1.setText("");
         } else {
         File arquivo = file.getSelectedFile();
         jTextField1.setText(arquivo.getPath());
         }
         */
    }//GEN-LAST:event_jButtonIncluirActionPerformed

    private void jRadioButtonPacienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonPacienteActionPerformed
        if (jRadioButtonPaciente.isSelected() == true) {
            jPanelPaciente.setVisible(true);
            jPanelMedico.setVisible(false);
            jPanelFuncionario.setVisible(false);
        }
    }//GEN-LAST:event_jRadioButtonPacienteActionPerformed

    private void jRadioButtonMedicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMedicoActionPerformed
        if (jRadioButtonMedico.isSelected() == true) {
            jPanelPaciente.setVisible(false);
            jPanelMedico.setVisible(true);
            jPanelFuncionario.setVisible(false);
        }
    }//GEN-LAST:event_jRadioButtonMedicoActionPerformed

    private void jRadioButtonFuncionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonFuncionarioActionPerformed
        if (jRadioButtonFuncionario.isSelected() == true) {
            jPanelPaciente.setVisible(false);
            jPanelMedico.setVisible(false);
            jPanelFuncionario.setVisible(true);
        }
    }//GEN-LAST:event_jRadioButtonFuncionarioActionPerformed

    private void jFormattedTextFieldCPFFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextFieldCPFFocusLost
        /*
         boolean isValidCPF = CNPJ.isValidCPF(jFormattedTextFieldCPF.getText());

         if (isValidCPF != true) {
         jLabelBarraStatus.setText("CPF Inválido!!!");
         threadR(jLabelBarraStatus);
         jFormattedTextFieldCPF.setText(null);
         }
         */
    }//GEN-LAST:event_jFormattedTextFieldCPFFocusLost

    private void jFormattedTextFieldNascimentoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextFieldNascimentoFocusLost
        /*
         if (!jFormattedTextFieldNascimento.getText().equals("  /  /    ")) {
         Date data = null;
         dataTexto = jFormattedTextFieldNascimento.getText();
         SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
         try {
         format.setLenient(false);
         data = (Date) format.parse(dataTexto);
         } catch (ParseException e) {
         jLabelBarraStatus.setText("Data Inválida!!!");
         threadR(jLabelBarraStatus);
         dataTexto = null;
         jFormattedTextFieldNascimento.setText("");
         }
         }
         */



        String pattern = "dd/MM/yyyy";

        SimpleDateFormat format = new SimpleDateFormat(pattern);
        try {
            Date date = format.parse(jTextFieldCadastro.getText());
            Date qtd = format.parse(jFormattedTextFieldNascimento.getText());
            //int qtd = Integer.parseInt(jFormattedTextFieldNascimento.getText());
            //date.setDate(qtd * 31);


            Calendar now = Calendar.getInstance();
            now.setTime(date);
            now.setTime(qtd);

            System.out.println("Current date : " + (now.get(Calendar.MONTH))
                    + "-"
                    + now.get(Calendar.DATE)
                    + "-"
                    + now.get(Calendar.YEAR));

            //add months to current date using Calendar.add method
            //now.add(Calendar.MONTH, (qtd - 1));

            System.out.println("date after 10 months : " + now.get(Calendar.DATE) + "/" + (now.get(Calendar.MONTH) + 1) + "/" + now.get(Calendar.YEAR));


            SimpleDateFormat out = new SimpleDateFormat("dd/MM/yyyy");
            String result = now.get(Calendar.DATE) + "/" + (now.get(Calendar.MONTH) + 1) + "/" + now.get(Calendar.YEAR);
            System.out.println("Result1 aqui: " + result);
            jTextFieldIdade.setText(result);
            System.out.println("Result2 aqui: " + qtd);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }//GEN-LAST:event_jFormattedTextFieldNascimentoFocusLost

    private void jButtonFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonFecharActionPerformed
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_jButtonFecharActionPerformed

    private void jFormattedTextFieldCPFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFormattedTextFieldCPFActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jFormattedTextFieldCPFActionPerformed

    private void jTextFieldNomeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldNomeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldNomeActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Fr_CadastroPessoa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Fr_CadastroPessoa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Fr_CadastroPessoa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Fr_CadastroPessoa.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Fr_CadastroPessoa().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupTPPessoa;
    private javax.swing.JButton jButtonAlterar;
    private javax.swing.JButton jButtonConsultaCidade;
    private javax.swing.JButton jButtonConsultar;
    private javax.swing.JButton jButtonExcluir;
    private javax.swing.JButton jButtonFechar;
    private javax.swing.JButton jButtonIncluir;
    private javax.swing.JComboBox jComboBoxEstadoCivil;
    private javax.swing.JComboBox jComboBoxSexo;
    private javax.swing.JComboBox jComboBoxTpSangue;
    private javax.swing.JFormattedTextField jFormattedTextFieldCPF;
    private javax.swing.JFormattedTextField jFormattedTextFieldCelular;
    private javax.swing.JFormattedTextField jFormattedTextFieldNascimento;
    private javax.swing.JFormattedTextField jFormattedTextFieldTelefone;
    private javax.swing.JLabel jLabelBairro;
    private javax.swing.JLabel jLabelBarraStatus;
    private javax.swing.JLabel jLabelCPF;
    private javax.swing.JLabel jLabelCRM;
    private javax.swing.JLabel jLabelCadastro;
    private javax.swing.JLabel jLabelCarteiraTrabalho;
    private javax.swing.JLabel jLabelCelular;
    private javax.swing.JLabel jLabelCidade;
    private javax.swing.JLabel jLabelCodigo;
    private javax.swing.JLabel jLabelComplemento;
    private javax.swing.JLabel jLabelConvenio;
    private javax.swing.JLabel jLabelCor;
    private javax.swing.JLabel jLabelEmail;
    private javax.swing.JLabel jLabelEndereco;
    private javax.swing.JLabel jLabelEstadoCivil;
    private javax.swing.JLabel jLabelIdade;
    private javax.swing.JLabel jLabelNascimento;
    private javax.swing.JLabel jLabelNaturalidade;
    private javax.swing.JLabel jLabelNome;
    private javax.swing.JLabel jLabelObservacao;
    private javax.swing.JLabel jLabelRG;
    private javax.swing.JLabel jLabelSexo;
    private javax.swing.JLabel jLabelTelefone;
    private javax.swing.JLabel jLabelTpSangue;
    private javax.swing.JPanel jPanalEndereco;
    private javax.swing.JPanel jPanelContato;
    private javax.swing.JPanel jPanelFuncionario;
    private javax.swing.JPanel jPanelMedico;
    private javax.swing.JPanel jPanelPaciente;
    private javax.swing.JPanel jPanelTPPessoa;
    private javax.swing.JRadioButton jRadioButtonFuncionario;
    private javax.swing.JRadioButton jRadioButtonMedico;
    private javax.swing.JRadioButton jRadioButtonPaciente;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTextArea jTextAreaObservacoes;
    private javax.swing.JTextField jTextFieldBairro;
    private javax.swing.JTextField jTextFieldCRM;
    private javax.swing.JTextField jTextFieldCadastro;
    private javax.swing.JTextField jTextFieldCarteiraTrabalho;
    public javax.swing.JTextField jTextFieldCidade;
    public javax.swing.JTextField jTextFieldCodCidade;
    private javax.swing.JTextField jTextFieldCodigo;
    private javax.swing.JTextField jTextFieldComplemento;
    private javax.swing.JTextField jTextFieldConvenio;
    private javax.swing.JTextField jTextFieldCor;
    private javax.swing.JTextField jTextFieldEMail;
    private javax.swing.JTextField jTextFieldEndereco;
    public javax.swing.JTextField jTextFieldEstado;
    private javax.swing.JTextField jTextFieldIdade;
    private javax.swing.JTextField jTextFieldIdentitade;
    private javax.swing.JTextField jTextFieldNaturalidade;
    public javax.swing.JTextField jTextFieldNome;
    // End of variables declaration//GEN-END:variables

    public void limpardados() {
        jTextFieldCodigo.setText(null);
        jTextFieldNome.setText(null);
        jComboBoxTpSangue.setSelectedItem("A+");
        jTextFieldCadastro.setText(null);
        jFormattedTextFieldNascimento.setText(null);
        jTextFieldIdade.setText(null);
        jComboBoxSexo.setSelectedItem("Masculino");
        jComboBoxEstadoCivil.setSelectedItem("Solteiro");
        jTextFieldNaturalidade.setText(null);
        jTextFieldCor.setText(null);
        jTextFieldIdentitade.setText(null);
        jFormattedTextFieldCPF.setText(null);
        jTextFieldEMail.setText(null);
        jTextFieldCodCidade.setText(null);
        jTextFieldCidade.setText(null);
        jTextFieldEstado.setText(null);
        jTextFieldEndereco.setText(null);
        jTextFieldBairro.setText(null);
        jTextFieldComplemento.setText(null);
        jFormattedTextFieldTelefone.setText(null);
        jFormattedTextFieldCelular.setText(null);
        jTextAreaObservacoes.setText(null);
    }

    private void cadastro() {
        try {
            SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
            BeanPessoa BP = new BeanPessoa();
            String cpf, cpf2;
            cpf = jFormattedTextFieldCPF.getText().replace(".", "");
            cpf2 = cpf.replace("-", "");
            BP.setCod_pessoa(cpf2);
            BP.setNom_pessoa(jTextFieldNome.getText());
            BP.setTp_sangue(jComboBoxTpSangue.getSelectedItem().toString());
            try {
                BP.setDt_cadastro(formatter.parse(jTextFieldCadastro.getText().replace("/", ".")));
            } catch (ParseException ex) {
                Logger.getLogger(Jp_CadastroPessoa.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                BP.setDt_nasc(formatter.parse(jFormattedTextFieldNascimento.getText().replace("/", ".")));
            } catch (ParseException ex) {
                Logger.getLogger(Jp_CadastroPessoa.class.getName()).log(Level.SEVERE, null, ex);
            }
            BP.setIdade(Integer.valueOf(jTextFieldIdade.getText()));

            if (jComboBoxSexo.getSelectedItem().toString().equals("Masculino")) {
                BP.setSexo("M");
            } else {
                BP.setSexo("F");
            }
            BP.setEst_civil(jComboBoxEstadoCivil.getSelectedItem().toString());
            BP.setNaturalidade(jTextFieldNaturalidade.getText());
            BP.setCor_pele(jTextFieldCor.getText());
            BP.setIdentidade(jTextFieldIdentitade.getText());
            BP.setCpf(jFormattedTextFieldCPF.getText());
            BP.setEmail(jTextFieldEMail.getText());
            BP.setCod_cidade(Integer.valueOf(jTextFieldCodCidade.getText()));
            BP.setEndereco(jTextFieldEndereco.getText());
            BP.setBairro(jTextFieldBairro.getText());
            BP.setComplemento(jTextFieldComplemento.getText());
            BP.setTelefone(jFormattedTextFieldTelefone.getText());
            BP.setCelular(jFormattedTextFieldCelular.getText());
            BP.setObservacao(jTextAreaObservacoes.getText());

            if (jRadioButtonPaciente.isSelected() == true) {
                BP.setTp_pessoa("P");
            }

            if (jRadioButtonMedico.isSelected() == true) {
                BP.setTp_pessoa("M");
            }
            if (jRadioButtonFuncionario.isSelected() == true) {
                BP.setTp_pessoa("F");
            }

            CRUDPessoa dao = new CRUDPessoa();
            dao.adiciona(BP);
            limpardados();
        } catch (SQLException ex) {
            Logger.getLogger(Jp_CadastroPessoa.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void threadR(final JLabel label) {
        Thread tThread = new Thread(new Runnable() {
            @Override
            public void run() {

                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {

                    e.printStackTrace();
                }
                //repaint();    
                label.setText("");

            }
        });
        tThread.start();
    }
}
